package main

import (
	"fmt"
	"time"

	"gitee.com/sillyman/simpleUtil/common/gothrottler"
	"gitee.com/sillyman/simpleUtil/common/randx"
)

func main() {
	th := gothrottler.New(3) // 最大并发数为3

	for i := 0; i < 20; i++ {
		fn := func(args ...interface{}) {
			time.Sleep(time.Duration(randx.Integer(500, 2000)) * time.Millisecond)

			idx := args[0].(int)
			fmt.Printf("GoRoutine#%d: Now = %s\n", idx, time.Now().Format("15:04:05.9999"))
		}

		th.AddJob(fn, i)
	}

	th.Wait() // 等待所有任务结束
}
